#include "Globals.h"
#include "ifsm.h"

//--------------------------------------------------------------------------------
//	initialize an fsm asset
//--------------------------------------------------------------------------------
void *IFSM::AssetInit( IAssetFile *pi, const CMasterIndexEntry *pme, void *context )
{
	IFSM			*ret;
	CHashListItem	*items;
	CFSMState		*pState;
	u32				i;

	ret = (IFSM*)pi->GetChunk(pme->nameHash,pme->primaryChunk);
	if( ret )
	{
		// initialize the hash list
		pi->SetupHashList(&ret->states,ret);
		pi->SetupHashList(&ret->dictionary,ret);

		ret->nameString = pi->GetName(pme->nameHash);

		// initialize the states
		items = (CHashListItem*)ret->states.GetData();
		for( i=0;i<ret->states.GetNItems();i++ )
		{
			pState = (CFSMState*)items[i].data;
			pState->nameString = ret->GetText(pState->name);
			pi->SetupHashList(&pState->events,ret);
		}

	}
	return (void*)ret;
}

//--------------------------------------------------------------------------------
//	uninitialize an fsm asset
//--------------------------------------------------------------------------------
void IFSM::AssetUninit( void *ptr, void *context )
{
}

//--------------------------------------------------------------------------------
//	fixup an asset
//--------------------------------------------------------------------------------
void IFSM::AssetFixup( CAssetFileMgr *pMgr, const IAssetFile *pFile, void *ptr, const CMasterIndexEntry *pEntry )
{
	IFSM *pFSM = (IFSM*)ptr;
	if( pFSM->parentName )
		pFSM->parent = (CFSMDef*)pMgr->FindAsset(pFSM->parentName,"FSM");
}
